

package frontera;


import Control.CrudCompra;
import Control.CrudProducto;
import Entidad.Compra;
import Entidad.Sistema;
import Entidad.Tarea;
import Control.CrudTarea;
import Entidad.Cliente;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
import javax.swing.JTable;
/**
 *
 * @author Stiv
 */
public class PanelTareas extends javax.swing.JPanel {

    public static DefaultTableModel dtmtareas;
    
    public PanelTareas() {
        initComponents();
        inicializar();
    }
    
    public boolean isCellEditable (int row, int column)
        {
       // Aquí devolvemos true o false según queramos que una celda
       // identificada por fila,columna (row,column), sea o no editable
       if (column == 4)
          return true;
       return false;
   }
    

    public void inicializar(){

        //this.setSize(1200, 800);
        NuevaTareaBT.setVisible(true);
        dtmtareas = new DefaultTableModel(new Object[][] {
		}, new String[] { "Estado","ID de Compra", "ID","Fecha", "Tipo", "Asignada"}){};
        TablaTareas.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS); 
        
        
        PanelInfo.setVisible(false);
        
        Cliente nuevo = new Cliente("Damian Diaz",80765500,"Cll 210 n° 45-24",2253775);
        
        CrudCompra.crearCompra( 800000, "12,9,22",CrudProducto.bringAll(), nuevo);

           
        Calendar a = Calendar.getInstance();
        
        a.set(2012, 8 , 26);
        
        
        

        
       CrudTarea.crearTarea("Preparado", a, a,"Envio","envio de mercancia al cliente en las horas de la mañana",
                CrudCompra.consultarCompra(1));
       CrudTarea.crearTarea("Preparado", a, a,"Servicio Tecnico","Mantenimiento de mercancia",CrudCompra.consultarCompra(1));
       
       TablaTareas.setModel(dtmtareas);        
        
       for(Entidad.Tarea p: CrudTarea.bringAll()){
           
           dtmtareas.addRow(new Object[]{p.getEstado(), p.getCompra().getID() , p.getID(),p.getFecha_fin().getTime(),
           p.getTipo(), "Andres EScobar"});
          
       
               }
    }
    
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        TablaTareas = new javax.swing.JTable();
        jSeparator1 = new javax.swing.JSeparator();
        NuevaTareaBT = new javax.swing.JButton();
        PanelInfo = new javax.swing.JPanel();
        NombreClienteTF = new javax.swing.JTextField();
        TelefonoTF = new javax.swing.JTextField();
        DireccionTF = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        AsuntoTF = new javax.swing.JTextField();

        setPreferredSize(new java.awt.Dimension(1000, 869));

        TablaTareas.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        TablaTareas.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                TablaTareasMouseReleased(evt);
            }
        });
        jScrollPane1.setViewportView(TablaTareas);

        NuevaTareaBT.setText("Nueva Tarea");
        NuevaTareaBT.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                NuevaTareaBTActionPerformed(evt);
            }
        });

        jLabel5.setText("Nombre");

        jLabel6.setText("Telefono");

        jLabel7.setText("Direccion");

        jLabel8.setText("Asunto");

        javax.swing.GroupLayout PanelInfoLayout = new javax.swing.GroupLayout(PanelInfo);
        PanelInfo.setLayout(PanelInfoLayout);
        PanelInfoLayout.setHorizontalGroup(
            PanelInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(PanelInfoLayout.createSequentialGroup()
                .addGroup(PanelInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(PanelInfoLayout.createSequentialGroup()
                        .addGap(22, 22, 22)
                        .addGroup(PanelInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(jLabel6)
                            .addComponent(jLabel5))
                        .addGap(0, 0, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, PanelInfoLayout.createSequentialGroup()
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jLabel7)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(PanelInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(NombreClienteTF, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 198, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(DireccionTF, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 198, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(TelefonoTF, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 198, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(75, 75, 75)
                .addComponent(jLabel8)
                .addGap(18, 18, 18)
                .addComponent(AsuntoTF, javax.swing.GroupLayout.PREFERRED_SIZE, 318, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        PanelInfoLayout.setVerticalGroup(
            PanelInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, PanelInfoLayout.createSequentialGroup()
                .addGap(27, 27, 27)
                .addGroup(PanelInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(AsuntoTF)
                    .addGroup(PanelInfoLayout.createSequentialGroup()
                        .addGroup(PanelInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(NombreClienteTF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel5)
                            .addComponent(jLabel8))
                        .addGap(32, 32, 32)
                        .addGroup(PanelInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(TelefonoTF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel6))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 35, Short.MAX_VALUE)
                        .addGroup(PanelInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(DireccionTF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel7))))
                .addGap(22, 22, 22))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jScrollPane1)
                        .addContainerGap())
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addComponent(jSeparator1)
                                .addComponent(PanelInfo, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                            .addComponent(NuevaTareaBT))
                        .addGap(0, 56, Short.MAX_VALUE))))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(73, 73, 73)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 286, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 18, Short.MAX_VALUE)
                .addComponent(NuevaTareaBT)
                .addGap(18, 18, 18)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(PanelInfo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

    private void TablaTareasMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_TablaTareasMouseReleased
        
        TablaTareas.addMouseListener(new MouseAdapter() 
   {
      public void mouseClicked(MouseEvent e) 
      {
         int fila = TablaTareas.getSelectedRow();
            int id = (int)dtmtareas.getValueAt(fila,2); 
            for(Entidad.Tarea u: Sistema.getTarea()){
                if(u.getID() == id){
                    Cliente tempo = new Cliente();
                    tempo = CrudTarea.obtenerCliente(id);
                    AsuntoTF.setText(u.getDescripcion());
                    NombreClienteTF.setText(tempo.getNombre());
                    NombreClienteTF.setVisible(true);
                    TelefonoTF.setText(String.valueOf(tempo.getTelefono()));
                    DireccionTF.setText(tempo.getDireccion());
                    PanelInfo.setVisible(true);
                    
                    
                }
            
                }
                
         
      }
   });
    }//GEN-LAST:event_TablaTareasMouseReleased

    private void NuevaTareaBTActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_NuevaTareaBTActionPerformed
        CrearTarea nueva = new CrearTarea();
        nueva.setVisible(true);
    }//GEN-LAST:event_NuevaTareaBTActionPerformed

    
    
    
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextField AsuntoTF;
    private javax.swing.JTextField DireccionTF;
    private javax.swing.JTextField NombreClienteTF;
    private javax.swing.JButton NuevaTareaBT;
    private javax.swing.JPanel PanelInfo;
    private javax.swing.JTable TablaTareas;
    private javax.swing.JTextField TelefonoTF;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JSeparator jSeparator1;
    // End of variables declaration//GEN-END:variables
}
